import os
import json
import zipfile
import math


def gcd(a, b):
    r = a % b
    return gcd(b, r) if r != 0 else b


def lcm(a, b):
    return a * b // gcd(a, b)


def gaussian_weight(steps, std_dev, half=False):
    dq = std_dev * std_dev

    def f(_x):
        return math.pow(2.0 * math.pi * dq, -0.5) * math.exp(-0.5 * _x * _x / dq)

    s = f(0.0)
    x = 1.0
    w = [s]
    t = 1.0 if half else 2.0
    for i in range(steps):
        y = f(x)
        w.append(y)
        s += y * t
        x += 1.0
    for i in range(steps + 1):
        w[i] /= s
    return w


def sign(x):
    if x < 0:
        return -1
    elif x > 0:
        return 1
    else:
        return 0
